package com.iteaj.iot.client.modbus;

import com.iteaj.iot.client.ClientConnectProperties;
import com.iteaj.iot.client.MultiClientManager;
import com.iteaj.iot.client.TcpSocketClient;
import com.iteaj.iot.client.component.TcpClientComponent;
import com.iteaj.iot.client.modbus.message.ModbusTcpMessage;
import com.iteaj.iot.config.ConnectProperties;

public abstract class ModbusTcpClientComponent<M extends ModbusTcpMessage> extends TcpClientComponent<M> implements ModbusIdManager {

    private static final String DESC = "基于Modbus Tcp协议的Iot实现";

    private ModbusIdManager modbusIdManager;

    public ModbusTcpClientComponent(ClientConnectProperties config) {
        super(config);
        this.modbusIdManager = new SimpleModbusIdManager();
    }

    public ModbusTcpClientComponent(ClientConnectProperties config, ModbusIdManager modbusIdManager) {
        super(config);
        this.modbusIdManager = modbusIdManager;
    }

    public ModbusTcpClientComponent(ClientConnectProperties config, MultiClientManager clientManager, ModbusIdManager modbusIdManager) {
        super(config, clientManager);
        this.modbusIdManager = modbusIdManager;
    }

    @Override
    public TcpSocketClient createNewClient(ClientConnectProperties config) {
        return new ModbusTcpClient(this, config);
    }

    @Override
    public String getDesc() {
        return DESC;
    }

    @Override
    public short nextId() {
        return this.modbusIdManager.nextId();
    }
}
